#!/bin/bash
# Job yaml can send below ENVIRONMENT VARIABLES to me
# - testsuite
# - case
# END ENVIRONMENT VARIABLES

. $LKP_SRC/lib/upload.sh

cd $BENCHMARK_ROOT/test-tools/mugen || exit

dns_resolver()
{
	cat >> /etc/resolv.conf <<EOF
nameserver 114.114.114.114
nameserver 223.5.5.5
EOF
}

set_env()
{
	bash mugen.sh -c "$direct_server_ips" "$secrets_username" "$secrets_userpassword"
	bash mugen.sh -c "$direct_client_ips" "$secrets_username" "$secrets_userpassword"
}

download_cases()
{
	bash mugen.sh -d

	# skip os-basic, because not support test about rebooting testbox.
	mv suite2cases/os-basic .
}

test_one_case()
{
	bash mugen.sh -f "$testsuite" -Cr "$case"
}

test_one_testsuite()
{
	bash mugen.sh -f "$testsuite"
}

test_all_cases()
{
	bash mugen.sh -a
}

upload_results_logs()
{

	ls results/failed >> results/failed_list
	ls results/succeed >> results/succeed_list
	upload_files -t logs logs/*
	upload_files -t results results/failed_list
	upload_files -t results results/succeed_list
}

run()
{
	dns_resolver
	set_env
	download_cases
	if [ -n "$testsuite" ];then
		if [ -n "$case" ];then
			test_one_case
		else
			test_one_testsuite
		fi
	else
		test_all_cases
	fi
	upload_results_logs
}

run
